home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 12
/
Amiga Plus Sonderheft Amiga 12.iso
/
pd
/
spiele
/
klondike_adptools
/
install
/
datas
/
english.lha
/
2-ScalePics.adpro
< prev
next >
Wrap
Text File
|
1997-06-24
|
9KB
|
407 lines
/*
** ScalePics.adpro :
**
** This ARexx script for ADPro v2.5 or higher,
** scales selected pictures to 86x128 pixels and save them to IFF ILBM 24 bits.
**
** Klondike & Reko Tools © Copyright Reko Productions - All Rights Reserved.
**
** $VER: ScaleCards/English v2.0 (16.06.97) Copyright © 1995-97 Lejardinier Olivier - All Rights Reserved
**
*/
/*
** ARexx Initializations.
*/
ADDRESS "ADPro"
OPTIONS RESULTS
ReturnCode = 0
/*
** Constants Initializations.
*/
NL = '0A'X
DNL = NL || NL
FALSE = 0
TRUE = 1
/*
** Strings initializations.
*/
TITLE_Error = "Error :"
TITLE_Confirm = "Confirm :"
TITLE_SelectPictures = "Select some pictures to scale :"
TITLE_SelectDestination = "Select scaled pictures destination :"
TITLE_ScaledPicsBaseName = "Scaled pictures base name :"
TITLE_StartFileExtensionAt = "Start file extension at :"
MSG_Abort = "Abort ?"
MSG_ErrorCode = "Error code ="
MSG_ADProResult = "ADPro result ="
MSG_UnableToSaveADProPrefs = "Unable to save ADPro prefs."
MSG_UnableToRestoreADProPrefs = "Unable to restore ADPro prefs."
MSG_UnableToLoadPicture = "Unable to load picture :"
MSG_UnableToScalePicture = "Unable to scale picture :"
MSG_UnableToSavePicture = "Unable to save picture :"
MSG_ProcessingPicture = "Processing"
MSG_LoadingPicture = "Loading picture"
MSG_ScalingPicture = "Scaling picture to 86 * 128"
MSG_SavingPicture = "Saving scaled picture"
GAD_ContinueAbort = "Continue|Abort"
GAD_RetrySkipAbort = "Retry|Skip|Abort"
/*
** Save the current ADPro environment.
*/
TempDefaults = "T:TempADProDefaults"
SAVE_DEFAULTS '"'TempDefaults'"'
IF ( RC ~= 0 ) THEN
DO
Text = MSG_UnableToSaveADProPrefs || ADProResult()
OKAY1 '"'Text'"'
END
/*
** Initializations of new ADPro environment.
*/
CLOSE_RENDER_SCREEN
CLEAR_RENDERED
CLEAR_RAW
PSTATUS "UNLOCKED"
DISPLAYMESSAGE '""'
ADPRO_TO_FRONT
/*
** Get some pictures files to scale.
*/
PicsDir = GetPref( "KADPT.PicsDir" )
Continue = FALSE
DO UNTIL ( Continue = TRUE )
IF ( PicsDir ~= "" ) THEN
GETFILES '"'TITLE_SelectPictures'"' '"'ParseDir( PicsDir )'"' '""'
ELSE
GETFILES '"'TITLE_SelectPictures'"'
IF ( RC ~= 0 ) THEN
CALL ConfirmAbort
ELSE
DO
PicsList = ADPRO_RESULT
Continue = TRUE
END
END
PicFilePath = WORD( PicsList, 1 )
PicsDir = DirPart( PicFilePath )
SetPref( "KADPT.PicsDir", PicsDir )
/*
** Get destination directory for the scaled pics.
*/
ScaledPicsDir = GetPref( "KADPT.ScaledPicsDir" )
IF ( ScaledPicsDir = "" ) THEN
ScaledPicsDir = PicsDir
Continue = FALSE
DO UNTIL ( Continue = TRUE )
GETDIR '"'TITLE_SelectDestination'"' '"'ParseDir( ScaledPicsDir )'"'
IF ( RC ~= 0 ) THEN
CALL ConfirmAbort
ELSE
DO
ScaledPicsDir = ADPRO_RESULT
Continue = TRUE
END
END
SetPref( "KADPT.ScaledPicsDir", ScaledPicsDir )
/*
** Select scaled picture base name.
*/
ScaledPicsBaseName = GetPref( "KADPT.ScaledPicsBaseName" )
IF ( ScaledPicsBaseName = "" ) THEN
ScaledPicsBaseName = DelExt( FilePart( PicFilePath ) )
Continue = FALSE
DO UNTIL ( Continue = TRUE )
GETSTRING '"'TITLE_ScaledPicsBaseName'"' '"'ScaledPicsBaseName'"'
IF ( RC ~= 0 ) THEN
CALL ConfirmAbort
ELSE
DO
ScaledPicsBaseName = ADPRO_RESULT
Continue = TRUE
END
END
SetPref( "KADPT.ScaledPicsBaseName", ScaledPicsBaseName )
/*
** Get scaled picture extension filename counter starting.
*/
Extension = GetPref( "KADPT.Extension" )
IF ( Extension = "" ) THEN
Extension = 1
NbPics = WORDS( PicsList )
Continue = FALSE
DO UNTIL ( Continue = TRUE )
GETNUMBER '"'TITLE_StartFileExtensionAt'"' Extension 1 999-NbPics
IF ( RC ~= 0 ) THEN
CALL ConfirmAbort
ELSE
DO
Extension = ADPRO_RESULT
Continue = TRUE
END
END
/*
** Load, scale & save files to IFF ILBM 24 bits.
*/
LOAD_TYPE "REPLACE"
DO Index = 1 TO NbPics
PicPath = WORD( PicsList, Index )
ScaledPicName = AddExt( ScaledPicsBaseName, RIGHT( Extension, 3, '0' ) )
Processing = MSG_ProcessingPicture ScaledPicName ":"
Continue = FALSE
DO UNTIL ( Continue = TRUE )
Text = Processing MSG_LoadingPicture FilePart( PicPath )
DISPLAYMESSAGE '"'Text'"'
LOADER "UNIVERSAL" PicPath
IF ( RC ~= 0 ) THEN
DO
IF ( ADPRO_RESULT = "Aborted" ) THEN
CALL ConfirmAbort
ELSE
DO
Text = MSG_UnableToLoadPicture || DNL || ParseString( PicPath ) || ADProResult()
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'GAD_RetrySkipAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
ELSE
IF ( RC = 2 ) THEN
Continue = TRUE
END
END
ELSE
DO
Text = Processing MSG_ScalingPicture
DISPLAYMESSAGE '"'Text'"'
ABS_SCALE 86 128
IF ( RC ~= 0 ) THEN
IF ( ADPRO_RESULT = "Aborted" ) THEN
DO
CALL ConfirmAbort
END
ELSE
DO
Text = MSG_UnableToScalePicture || DNL || ParseString( PicPath ) || ADProResult()
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'GAD_RetrySkipAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
ELSE
IF ( RC = 2 ) THEN
Continue = TRUE
END
ELSE
DO
ScaledPicPath = AddPart( ScaledPicsDir, ScaledPicName )
Text = Processing MSG_SavingPicture ScaledPicName
DISPLAYMESSAGE '"'Text'"'
Continue0 = FALSE
DO UNTIL ( Continue0 = TRUE )
SAVER "IFF" ScaledPicPath "RAW"
IF ( RC ~= 0 ) THEN
DO
IF ( ADPRO_RESULT = "Aborted" ) THEN
CALL ConfirmAbort
ELSE
DO
Text = MSG_UnableToSavePicture || DNL || ParseString( ScaledPicPath ) || ADProResult()
ADDRESS COMMAND 'C:Delete >NIL: "' || ScaledPicPath || '" QUIET'
OKAYN '"'TITLE_Error'"' '"'Text'"' '"'GAD_RetrySkipAbort'"'
IF ( RC = 0 ) THEN
CALL ConfirmAbort
ELSE
IF ( RC = 2 ) THEN
DO
Continue0 = TRUE
Continue = TRUE
END
END
END
ELSE
DO
Extension = Extension + 1
Continue0 = TRUE
Continue = TRUE
END
END
END
END
END
END
SetPref( "KADPT.Extension", Extension )
/*
** Quit.
*/
Quit:
CLOSE_RENDER_SCREEN
CLEAR_RENDERED
CLEAR_RAW
DISPLAYMESSAGE '""'
IF ( EXISTS( TempDefaults ) ) THEN
DO
LOAD_DEFAULTS '"'TempDefaults'"'
IF ( RC ~= 0 ) THEN
DO
Text = MSG_UnableToRestoreADProPrefs || ADProResult()
OKAY1 '"'Text'"'
END
ADDRESS COMMAND 'C:Delete >NIL: FILE="' || TempDefaults || '" QUIET'
END
EXIT ReturnCode
RETURN
/*
** Sub Routines
*/
ADProResult:
ADProResultText = DNL || MSG_ErrorCode RC || NL || MSG_ADProResult ADPRO_RESULT
RETURN ADProResultText
ConfirmAbort:
OKAYN '"'TITLE_Confirm'"' '"'MSG_Abort'"' '"'GAD_ContinueAbort'"'
IF ( RC = 0 ) THEN
DO
ReturnCode = 20
CALL Quit
END
RETURN
ParseString: PROCEDURE
PARSE ARG String
RETURN STRIP( String, 'B', '"' )
ParseDir: PROCEDURE
PARSE ARG Dir
Dir = ParseString( Dir )
Dir = STRIP( Dir, 'T', '/' )
RETURN Dir
DirPart: PROCEDURE
PARSE ARG Path
Path = ParseString( Path )
FNameSepPos = LASTPOS( '/', Path )
IF ( FNameSepPos = 0 ) THEN
RETURN LEFT( Path, LASTPOS( ':', Path ) )
ELSE
RETURN LEFT( Path, FNameSepPos - 1 )
FilePart:
PARSE ARG Path
Path = ParseString( Path )
FNameSepPos = LASTPOS( '/', Path )
IF ( FNameSepPos = 0 ) THEN
FNameSepPos = LASTPOS( ':', Path )
RETURN RIGHT( Path, LENGTH( Path ) - FNameSepPos )
AddPart:
PARSE ARG Dir, Name
LastChar = RIGHT( Dir, 1 )
IF (( LastChar ~= "/" ) & ( LastChar ~= ":" )) THEN
Dir = Dir || "/"
RETURN Dir || Name
AddExt:
PARSE ARG Name, Ext
RETURN Name || "." || Ext
DelExt:
PARSE ARG Name
PointPos = LASTPOS( '.', Name )
if ( PointPos ~= 0 ) THEN
Name = DELSTR( Name, PointPos )
RETURN Name
GetPref: PROCEDURE
PARSE ARG Name
Pref = GETCLIP( Name )
IF ( Pref = "" ) THEN
DO
IF ( OPEN( FileHandle, AddPart( "ENVARC:Klondike_ADPTools", Name ), "READ" ) ) THEN
DO
Pref = READLN( FileHandle )
Dummy = CLOSE( FileHandle )
END
END
RETURN Pref
SetPref: PROCEDURE
PARSE ARG Name, Pref
Dummy = SETCLIP( Name, Pref )
IF ( ~EXISTS( "ENVARC:Klondike_ADPTools" ) ) THEN
ADDRESS COMMAND 'C:MakeDir >NIL: ENVARC:Klondike_ADPTools'
IF ( OPEN( FileHandle, AddPart( "ENVARC:Klondike_ADPTools", Name ), "WRITE" ) ) THEN
DO
Dummy = WRITELN( FileHandle, Pref )
Dummy = CLOSE( FileHandle )
END
RETURN Pref